package com.huaxin.hxmoduleworkorder.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huaxin.hxmoduleworkorder.dto.request.MaintenanceOrderProcessCreateReqDTO;
import com.huaxin.hxmoduleworkorder.mapper.MaintenanceOrderProcessMapper;
import com.huaxin.hxmoduleworkorder.mapping.MaintenanceOrderProcessMapping;
import com.huaxin.hxmoduleworkorder.models.MaintenanceOrderProcess;
import com.huaxin.hxmoduleworkorder.service.MaintenanceOrderProcessService;
import lombok.RequiredArgsConstructor;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class MaintenanceOrderProcessServiceImpl extends ServiceImpl<MaintenanceOrderProcessMapper, MaintenanceOrderProcess> implements MaintenanceOrderProcessService {
    private final ApplicationContext applicationContext;
    private final MaintenanceOrderProcessMapping mapping;

    @Override
    public Boolean create(MaintenanceOrderProcessCreateReqDTO in) {
        if (in == null) {
            return false;
        }
        MaintenanceOrderProcess entity = mapping.toEntity(in);
        return this.save(entity);
    }

    @Override
    public List<MaintenanceOrderProcess> getProcessHistory(String orderId) {
        LambdaQueryWrapper<MaintenanceOrderProcess> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(MaintenanceOrderProcess::getMaintenanceOrderId, orderId)
                .orderByAsc(MaintenanceOrderProcess::getCreatedAt);
        return this.baseMapper.selectList(wrapper);
    }
}